package com.tanhua.manager.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tanhua.manager.mapper.OptionMapper;
import com.tanhua.manager.service.OptionService;
import com.tanhua.pojo.Option;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OptionServiceImpl extends ServiceImpl<OptionMapper, Option> implements OptionService {
   @Autowired
   OptionMapper optionMapper;

    @Override
    public Boolean insertOne(Option option) {
        int insert = optionMapper.insert(option);
        if (insert == 1) {

            return true;
        }
        return false;
    }

    @Override
    public IPage<Option> findByPage(Integer pageNum, Integer pageSize) {

        IPage<Option> page = new Page<>(pageNum, pageSize);
        IPage<Option> optionIPage = optionMapper.selectPage(page, null);
        return optionIPage;
    }

    @Override
    public boolean deleteById(Integer id){

        int i = optionMapper.deleteById(id);
        return i>0;

    }

    @Override
    public List<Option> findByQuestionId(Integer questionId) {
        QueryWrapper<Option> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("question_id",questionId);
        return optionMapper.selectList(queryWrapper);
    }
}
